package com.jscq.yygh.user.service.impl;

import com.atguigu.yygh.enums.DictEnum;
import com.atguigu.yygh.model.user.StudentDetail;
import com.atguigu.yygh.vo.hosp.OrderVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jscq.cmn.client.DictFeignClient;
import com.jscq.yygh.user.mapper.StudentDetailMapper;
import com.jscq.yygh.user.service.StudentDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentDetailServiceImpl extends ServiceImpl<StudentDetailMapper, StudentDetail> implements StudentDetailService {

    @Autowired
    private DictFeignClient dictFeignClient;

    @Override
    public List<StudentDetail> findAllUserId(Long userId) {
        //根据userId查询学生详情
        QueryWrapper<StudentDetail> wrapper=new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        List<StudentDetail> studentDetails = baseMapper.selectList(wrapper);

        //远程调用dict 得到编码对应内容
        studentDetails.stream().forEach(item ->{
            this.packStudentDetail(item);
        });
        return studentDetails;
    }

    @Override
    public StudentDetail getStudentDetailId(long id) {
        return this.packStudentDetail(baseMapper.selectById(id));
    }

    @Override
    public StudentDetail getStudentDetailId(String stuCode) {
        QueryWrapper<StudentDetail> queryWrapper=new QueryWrapper();
        queryWrapper.eq("certificates_no",stuCode);
        StudentDetail studentDetail = new StudentDetail();
        studentDetail=baseMapper.selectOne(queryWrapper);

        return studentDetail;
    }



    // 参数封装
    private StudentDetail packStudentDetail(StudentDetail item) {
        //根据证件类型编码，获取证件类型具体指
        String certificatesTypeString =
                dictFeignClient.getName(DictEnum.CERTIFICATES_TYPE.getDictCode(), item.getCertificatesType());//联系人证件
        //联系人证件类型
        String contactsCertificatesTypeString =
                dictFeignClient.getName(DictEnum.CERTIFICATES_TYPE.getDictCode(),item.getContactsCertificatesType());
        //省
        String provinceString = dictFeignClient.getName(item.getProvinceCode());
        //市
        String cityString = dictFeignClient.getName(item.getCityCode());
        //区
        String districtString = dictFeignClient.getName(item.getDistrictCode());
        item.getParam().put("certificatesTypeString", certificatesTypeString);
        item.getParam().put("contactsCertificatesTypeString", contactsCertificatesTypeString);
        item.getParam().put("provinceString", provinceString);
        item.getParam().put("cityString", cityString);
        item.getParam().put("districtString", districtString);
        item.getParam().put("fullAddress", provinceString + cityString + districtString + item.getAddress());
        return item;

    }
}
